﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DicomDemo;
using Leadtools.Dicom;
using Leadtools.DicomDemos;

namespace DICOMViewer.Utility
{
    public class DicomDirMaker
    {
        private  DicomDirMaker()
        {
            
        }
        public static void CreateDicomDirectory(string workPath)
        {
            try
            {
                UserDicomDir dicomDir = new UserDicomDir();
                // Reset the DICOM Directory and set the destination folder where
                // the DICOMDIR file wiUserDicomDirll be saved
                dicomDir.Reset(workPath);

                // If it is desired to change the values of the Implementation Class
                // UID (0002,0012) and the Implementation Version Name (0002,0013)...
                DicomElement element;
                element = dicomDir.DataSet.FindFirstElement(null, DemoDicomTags.ImplementationClassUID, false);
                if (element != null)
                {
                    dicomDir.DataSet.SetStringValue(element, "1.2.840.114257.0.1", DicomCharacterSetType.Default); // Must be a UID
                }
                element = dicomDir.DataSet.FindFirstElement(null, DemoDicomTags.ImplementationVersionName, false);
                if (element != null)
                {
                    dicomDir.DataSet.SetStringValue(element, "LEADTOOLS 15", DicomCharacterSetType.Default); // Must be a UID
                }

                // Set options
                DicomDirOptions options = dicomDir.Options;
                options.IncludeSubfolders = true;
                options.InsertIconImageSequence = false;
                options.RejectInvalidFileId = false;
                dicomDir.Options = options;

                // Add the DICOM files to the DICOM Directory.
                // This is the function that does it all!
                // You can always give the user feedback about the progress inside 
                // this function by overriding the function DicomDir.OnInsertFile.   
                dicomDir.InsertFile(null);
                dicomDir.Save();

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
